package de.stefanocke.roo.kontaktliste.web;

import java.util.GregorianCalendar;

import org.apache.wicket.ConverterLocator;
import org.apache.wicket.IConverterLocator;
import org.apache.wicket.Page;
import org.apache.wicket.feedback.FeedbackMessage;
import org.apache.wicket.feedback.IFeedbackMessageFilter;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import org.apache.wicket.util.convert.converter.CalendarConverter;

import de.stefanocke.roo.wicket.RooStereotype;

/**
 * Application object for the Wicket web application.
 */
@RooStereotype("wicket.Application")
public class WicketApplication extends WebApplication {
	/**
	 * @see wicket.Application#getHomePage()
	 */
	@Override
	public Class<? extends Page> getHomePage() {
		return KontaktCrudPage.class;
	}

	@Override
	protected void init() {
		super.init();
		getComponentInstantiationListeners().add(new SpringComponentInjector(this));
		//Do not clean feedback messages, to allow them to survive AJAX requests
		getApplicationSettings().setFeedbackMessageCleanupFilter(new IFeedbackMessageFilter() {
			
			@Override
			public boolean accept(FeedbackMessage message) {
				return false;
			}
		});

	}

	@Override
	protected IConverterLocator newConverterLocator() {
		ConverterLocator converterLocator = new ConverterLocator();
		// necessary, since CalendarConverter is registered only for Calendar,
		// but not for its subclasses.
		converterLocator.set(GregorianCalendar.class, new CalendarConverter());
		return converterLocator;
	}

}
